// AI 服务配置

export const AI_CONFIG = {
  // DeepSeek 模型配置
  DEEPSEEK: {
    baseURL: import.meta.env.DEV ? '/api/ai' : 'http://8.141.30.224:8000/v1', // 开发环境使用代理
    model: 'deepseek-chat',
    apiKey: undefined, // 您的服务不需要 API Key
  },

  // 请求配置
  REQUEST: {
    timeout: 30000, // 30秒超时
    retries: 2, // 重试次数
    temperature: 0.7, // 创意度
    maxTokens: 1500, // 最大响应长度
  },

  // 功能开关
  FEATURES: {
    sceneGeneration: true, // 场景生成
    wordDefinition: true, // 单词定义
    healthCheck: true, // 健康检查
    fallbackToMock: true, // 降级到模拟数据
  },

  // 场景生成配置
  SCENE: {
    defaultDifficulty: 'intermediate' as const,
    defaultSceneType: 'daily' as const,
    maxWords: 10,
    minWords: 3,
  },

  // 提示词模板
  PROMPTS: {
    sceneGeneration: {
      system: 'You are SceneLingo, an innovative scene-based English learning assistant. Generate realistic, immersive learning scenarios that help users memorize English words through vivid contextual experiences. IMPORTANT: Always respond with ONLY valid JSON format - no markdown code blocks, no explanations, just pure JSON.',
      template: (words: string[], difficulty: string, sceneType: string, language: string) => {
        const difficultyMap = {
          beginner: language === 'zh' ? '初级' : 'beginner',
          intermediate: language === 'zh' ? '中级' : 'intermediate', 
          advanced: language === 'zh' ? '高级' : 'advanced'
        };

        const sceneTypeMap = {
          daily: language === 'zh' ? '日常生活' : 'daily life',
          business: language === 'zh' ? '商务办公' : 'business',
          academic: language === 'zh' ? '学术研究' : 'academic',
          travel: language === 'zh' ? '旅行出游' : 'travel'
        };

        return language === 'zh' 
          ? `请为英语学习者创建一个${difficultyMap[difficulty as keyof typeof difficultyMap]}难度的${sceneTypeMap[sceneType as keyof typeof sceneTypeMap]}场景，该场景需要自然地包含以下英语单词：${words.join(', ')}。

要求：
1. 场景要真实、生动、容易理解
2. 每个单词都要在场景中有明确的上下文
3. 为图像生成提供详细的场景描述
4. 为每个单词指定在图像中的大致位置（百分比坐标）

请以纯JSON格式返回（不要使用markdown代码块）：
{
  "title": "场景标题",
  "description": "场景的详细中文描述，200字左右",
  "imagePrompt": "用于AI图像生成的英文提示词，详细描述场景的视觉元素",
  "wordContexts": [
    {
      "word": "单词",
      "contextDescription": "该单词在场景中的具体用途和上下文说明",
      "position": {
        "x": 25,
        "y": 30
      }
    }
  ]
}

注意：position的x和y值应该是0-100之间的百分比，表示单词在图像中的大致位置。`
          : `Create a ${difficultyMap[difficulty as keyof typeof difficultyMap]} level ${sceneTypeMap[sceneType as keyof typeof sceneTypeMap]} learning scenario that naturally incorporates the following English words: ${words.join(', ')}.

Requirements:
1. The scenario should be realistic, vivid, and easy to understand
2. Each word should have clear context within the scenario
3. Provide detailed scene description for image generation
4. Specify approximate positions for each word in the image (percentage coordinates)

Please return ONLY pure JSON format (no markdown code blocks):
{
  "title": "Scene Title",
  "description": "Detailed description of the scene, around 200 words",
  "imagePrompt": "English prompt for AI image generation, describing visual elements in detail",
  "wordContexts": [
    {
      "word": "word",
      "contextDescription": "Specific usage and context of this word in the scene",
      "position": {
        "x": 25,
        "y": 30
      }
    }
  ]
}

Note: x and y values in position should be percentages between 0-100, representing the approximate position of the word in the image.`;
      }
    },

    wordDefinition: {
      system: 'You are an English dictionary assistant. Provide accurate word definitions, pronunciations, and examples. IMPORTANT: Always respond with ONLY valid JSON format - no markdown code blocks, no explanations, just pure JSON.',
      template: (word: string, language: string) => 
        language === 'zh' 
          ? `请为英语单词 "${word}" 提供中文释义、音标、词性和3个例句。以纯JSON格式返回（不要使用markdown代码块）：{"definition": "中文释义", "pronunciation": "音标", "partOfSpeech": "词性", "examples": ["例句1", "例句2", "例句3"]}`
          : `Please provide definition, pronunciation, part of speech, and 3 examples for the English word "${word}". Return ONLY pure JSON format (no markdown code blocks): {"definition": "definition", "pronunciation": "phonetic", "partOfSpeech": "part of speech", "examples": ["example1", "example2", "example3"]}`
    }
  }
};

export default AI_CONFIG;
